from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from garetjax.locations.models import Location
from garetjax.taxonomy.models import Category

class Event(models.Model):
    title = models.CharField(_('title'), max_length=100)
    description = models.TextField(_('description'), blank=True)
    date_start = models.DateField(_('start date'))
    time_start = models.TimeField(_('start time'), blank=True, null=True)
    date_end = models.DateField(_('end date'), blank=True, null=True)
    time_end = models.TimeField(_('end time'), blank=True, null=True)
    banner = models.ImageField(_('banner'), upload_to="assets/event_banners", blank=True, null=True)
    location = models.ForeignKey(Location, verbose_name=_('location'), blank=True, null=True)
    category = models.ForeignKey(Category, verbose_name=_('category'),  blank=True, null=True)
    
    def __unicode__(self):
        return '%s del %s' % (self.title, self.date_start)
    
    class Meta:
        ordering = ('date_start', 'time_start')

class Reservation(models.Model):
    event = models.OneToOneField(Event)
    reservation_open = models.BooleanField(default=True)
    max_num = models.PositiveIntegerField(blank=True, null=True)
    attendees = models.ManyToManyField(User)
    
    def __unicode__(self):
        return 'Reservation for: %s' % self.event.title
    